String[] list = new String[3];
list[3] = "dog" ;
An ArrayIndexOutOfBounds
exception is thrown and
(ordinarily) the program halts.
Vector
class
The Vector
class builds upon the capabilities of arrays.
A Vector
object contains an array of object references
plus many methods for managing that array.
The biggest convenience of a Vector
is that you can
keep adding elements to it no matter what size it was originally.
The size of the Vector
will automatically increase
and no information will be lost.
However, this convenience comes at a price:
Vector
are object references,
not primitive data like int
or double
.Vector
is slighly slower than using
an array directly.Vector
are references to Object
.
This means that often you will need to use type casting with
the data from a Vector
.